//
//  LYComposeButton.swift
//  微博
//
//  Created by liuerying on 16/5/28.
//  Copyright © 2016年 liuerying. All rights reserved.
//

import UIKit
//图片高度
private let imageHeight:CGFloat = 80

class LYComposeButton: UIButton {
    
    //添加模型
    var composeItem:LYComposeItems?{
    
        didSet{
        
            setImage(UIImage(named: composeItem?.icon ?? ""), forState: .Normal)
        
            setTitle(composeItem?.title, forState: .Normal)
            titleLabel?.textAlignment = .Center
            titleLabel?.font = UIFont.systemFontOfSize(14)
            setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        }
        
        
    }
    
    
    //改变文字的位置
    override func titleRectForContentRect(contentRect: CGRect) -> CGRect {
        
        //按钮的高是120,图片的高是80.
        return CGRect(x: 0, y: imageHeight, width: imageHeight, height: contentRect.height-imageHeight)
    }
    
    //改变图片的位置
    override func imageRectForContentRect(contentRect: CGRect) -> CGRect {
        
        return CGRect(x: 0, y: 0, width:imageHeight, height: imageHeight)
    }

}
